#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdlib>
#include <map>
#include <bitset>
#include <unordered_map>
#include <ctime>
#include <vector>
#include <queue>
#include <list>
#include <stack>

#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned
using namespace std;
I LL read()
{
    R LL   x;
    R bool f;
    R char c;
    for(f=0;(c=getchar())<'0'||c>'9';f=c=='-');
    for(x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct person{
    int age,nw;
    char name[100];
};
#define MAXN 100011
person persons[MAXN];
bool cmp(const person &a,const person &b)
{
    return (a.nw!=b.nw)?(a.nw>b.nw):((a.age!=b.age)?a.age<b.age:strcmp(a.name,b.name)<0);
}
int main()
{
    freopen("7-4.in","r",stdin);
    //freopen("7-4.out","w",stdout);
    int n=read(),k=read();
    for(int i=0;i<n;scanf("%s %d %d",persons[i].name,&persons[i].age,&persons[i].nw),++i);
    sort(persons,persons+n,cmp);
    for(int t=1;t<=k;++t)
    {
        printf("Case #%d:\n",t);
        int a=read(),b=read(),c=read();
        bool f=true;
        for(int i=0;i<n&&a;++i)
            if(persons[i].age>=b&&persons[i].age<=c)
                f=false,--a,printf("%s %d %d\n",persons[i].name,persons[i].age,persons[i].nw);
        if(f)
            printf("None\n");
    }
    
    
    fclose(stdin);
    fclose(stdout);
    return 0;
}